#ifndef __ULISTCTRL_H__
#define __ULISTCTRL_H__
#include "VUIControl.h"

struct ULCITEM 
{
	const char* tableEntryText;
	BOOL        isSelected;
	void*       itemDate;
};

class UIAPI UListCtrl : public VUIControl
{
	UDEC_CLASS(UListCtrl);
public:
	
	UListCtrl(void);
	virtual ~UListCtrl(void);
protected:
	int GetItemCount();
	int GetSelectCount();
    int GetSelectedItem();
	//void GetSelectedItems(vector<int> &Items);
	int GetItemIndex(ULCITEM* item);
	const char* GetItemText(int index);

	void SetCurSelected(int index);
	void SetCurSelectedRang(int start , int stop);
	void SetItemText(int index,const char* text);

	int AddItem(const char* text, void*itemDate = NULL);
	void AddSeletion(ULCITEM *item, int index );
	int InsertItem(int index, const char* text,void*itemDate = NULL);
	int FindItemByText(const char* text,BOOL caseSensitive = FALSE);

	void DeleteItem(int index);
	void ClearItems();
	void ClearSelection();
	void RemoveSelection(ULCITEM* item, int index);
	void RemoveSelection(int index);

	inline void SetMultipleSelection(BOOL allowMultipleSelect = TRUE){m_MultipeSelections = allowMultipleSelect;}

	void UpdateSize();
	virtual void OnRenderItem( VRect itemRect, ULCITEM *item );
	void DrawBox(const VPoint &box, int size, VColor &outlineColor, VColor &boxColor);
	static int        getStringElementCount( const char *inString );
	static const char* getStringElement( const char* inString, const int index );
protected:
	virtual BOOL OnCreate();
	virtual void OnDestroy();
	virtual void OnRender(const VPoint& offset, const VRect &updateRect);
	virtual void OnMouseDown(const VPoint& point, UINT nRepCnt, UINT uFlags);
	virtual void OnMouseDragged(const VPoint& position, UINT flags);
protected:
	BOOL           m_MultipeSelections;
	VPoint         m_ItemSize;
	BOOL           m_FitParentWidth;
	ULCITEM*        m_LastClickItem;
	struct ListCtrlContex* m_pListCtx ;
};
#endif